var app = new Vue({
	el:"#xp-wrapper",	
	data: {
		Leibie:[],
		xinzhi:[],
		king : false,
		dlx: false,
		dlx2: false,
		xianshi: "",
		xiala : "",
		a : "",
		username : "",
		dhua : "",
		xbie : "",
		sfz : "",
		leibies : "",
		neirong : "",
		dhking : false,
		xbking : false,
		sfzking : false,
		nameking : false,
		duixiang : [],
		oldnames : [],
		oldusername:""
	},
	mounted() {
		this.getleixing(),
		this.getleibie()
		// this.getle()
	},
	methods:{
		getleixing(){
			axios.post("laifang/senature")
			.then(response =>{
				this.Leibie=response.data.data
			})
		},
		getleibie(){
			axios.post("laifang/secategory")
			.then(response1 =>{
				this.xinzhi=response1.data.data
			})
		},
		dengllu(a){
			this.xiala=a
			if(localStorage.token=="null"){
				this.dlx2=true;
				if(a==1){
					this.xianshi="请输入老人姓名"
				}else if(a==2){
					this.xianshi="请输入活动内容"
				}else{
					this.xianshi="请输入来访详细"
				}
			}else{
				if(a==1){
					this.dlx=true
					console.log(localStorage.token)
					axios({
					    method: "get",
					    url:"yly-api/user/logon/queryUserInfo",
					    headers:{"token":localStorage.token}
					})
					.then(response =>{
						alert(1)
						this.duixiang=response.data.data.id
						let data= new URLSearchParams;
						data.append("id",this.duixiang);
						axios.post("laifang/laifangshijiao",data)
						.then(response =>{
							this.oldnames=response.data.data
							
						})
					})
				}else if(a==2){
					this.dlx2=true
					this.xianshi="请输入活动内容"
					this.dlx=false
				}else{
					this.dlx2=true
					this.xianshi="请输入来访详细"
					this.dlx=false
				}
				
			}
		},
		xingzhi(event){
			var a=event.target.value
			this.dengllu(a);
		},
		laor(event){
			console.log(event.target.value)
			var a=event.target.value;
			if(a==""){
				this.xianshi="请输入老人姓名"
				this.dlx2=true
			}else{
				this.dlx2=false
				this.oldusername=event.target.value;	
				this.neirong=event.target.value	
			}
		},
		leibie(event){
			this.leibies=event.target.value
		},
		name(event){
			if(event.target.value==""){
				this.nameking=true
			}else{
				this.nameking=false
			}
		},
		sfzz(event){
			if(event.target.value==""){
				this.sfzking=true
			}else{
				this.sfzking=false
			}
		},
		xb(event){
			if(event.target.value==""){
				this.xbking=true
			}else{
				this.xbking=false
			}
		},
		dh(event){
			if(event.target.value==""){
				this.dhking=true
			}else{
				this.dhking=false
			}
		},
		oldnamell(event){
			this.neirong=event.target.value
			if(this.xiala==1){
				this.a=event.target.value
				let data= new URLSearchParams;
				data.append("username",this.a);
				axios.post("laifang/selectOldName",data)
				.then(response =>{
					if(response.data.data!="ok"){
						this.king=true;
					}else {
						this.xianshi=this.neirong
						this.king=false;
					}
				})
			}else{
				return;
			}
		},
		shenghe(){
			if(this.king==true){
				alert("请输入正确的老人姓名在提交")
			}else{
				this.oldusername=app.username;
				var username =this.oldusername;
				if(username==""){
					this.nameking=true
				}
				var dhua=app.dhua;
				if(dhua==""){
					this.dhking=true
				}
				var sfz=app.sfz;
				if(sfz==""){
					this.sfzking=true
				}
				var xbie=app.xbie;
				if(xbie=="男"){
					xbie=1
				}else if(xbie=="女"){
					xbie=0
				}else{
					alert("请输入正确的性别")
				}
				var xingzhi=this.xiala;//性质
				var leibie=this.leibies;//类别
				var neirong=this.neirong;
				if(username==""){
					this.king=true;
				}
				if(this.nameking==false&&this.dhking==false&&this.sfzking==false&&this.king==false){
				let data =new URLSearchParams;
				data.append("username",username),
				data.append("phone",dhua),
				data.append("identitycode",sfz),
				data.append("sex",xbie),
				data.append("natureid",xingzhi),
				data.append("categoryid",leibie),
				data.append("particulars",neirong),
				axios.post("laifang/laifangsq",data)
				.then(response =>{
					alert("申请以提交")
				})
				}else{
					alert("请吧表填完")
				}
			}
		}
	}
})